<%--
  @author Duminda Dharmakeerthi
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<script src="${pageContext.request.contextPath}/js/printer.js" type="text/javascript"></script>
<%--<link rel="stylesheet" href="${pageContext.request.contextPath}/css/printDetailForm.css" media="print"/>--%>

<script type="text/javascript">
    $(function () {
        initData();
        $('select#gnDivisionId').bind('change', function (evt1) {
            initData();
        });
    });

    function initData() {
        var id = $('select#gnDivisionId').attr('value');
        var mode = "byGNDivision";
        var type = "unAlienatedLands";
        $.getJSON('${pageContext.request.contextPath}/common/LandLookupService', {id:id, mode:mode, type:type}, function (data) {
            loadLandList(data.landList);
            printReportHeader();
        });
    }

    function loadLandList(landInfo) {
        var opt = '';
        opt += '<thead>' +
                '<tr class="table-header">' +
                '<th class="center-align">' + $('#ref').val() + '</th>' +
                '<th class="left-align">' + $('#lname').val() + '</th>' +
                '<th class="center-align">' + $('#plan').val() + '</th>' +
                '<th class="center-align">' + $('#lot').val() + '</th>' +
                '<th class="center-align">' + $('#vil').val() + '</th>' +
                '<th class="center-align">' + $('#ext_pec').val() + '</th>' +
                '</tr>' +
                '</thead>';
        opt += '<tbody>';
        if (landInfo.length > 0) {
            for (var i = 0; i < landInfo.length; i++) {
                var reference = (landInfo[i].referenceNumber > 0) ? landInfo[i].referenceNumber : $('#undifined').val();
                var extent = (landInfo[i].kmlLandArea > 0) ?  landInfo[i].landExtent :0;
                extent = roundNumber(extent, 4);
                opt += '<tr>' +
                        '<td class="center-align">' + reference + '</td>' +
                        '<td>' + landInfo[i].nameOfTheLand + '</td>' +
                        '<td class="center-align">' + landInfo[i].planNumber + '</td>' +
                        '<td class="center-align">' + landInfo[i].lotNumber + '</td>' +
                        '<td class="center-align">' + landInfo[i].village + '</td>' +
                        '<td class="center-align">' + extent + '</td>' +
                        '</tr>';
            }
            $('.print-btn').val($('#print').val());
            $('.print-btn').show();
            $('#report-header').show();
        }
        opt += '</tbody>';
        $('.land-table').html(opt);
    }
    $(document).ready(function() {
        $('.print-btn').hide();
        $('#report-header').hide();
        $('.print-btn').printPreview({

        });
    });

    function printReportHeader() {
        $('#district').val($('#districtId').val());
        $('#ds-name').val($('#dsDivisionId').val());
        var selectedGN = document.getElementById('gnDivisionId').selectedIndex;
        var gnDivision = document.getElementById('gnDivisionId').options[selectedGN].text;
        $('#gn-name').val(gnDivision);
    }

    function roundNumber(number, decimals) { // Arguments: number to round, number of decimal places
        var newnumber = new Number(number + '').toFixed(parseInt(decimals));
        return parseFloat(newnumber);
    }


</script>
<div id="land-registration-module-home-title" class="module-home-title">
    <s:a href="reportModule.do">
        <span><img src="${pageContext.request.contextPath}/images/print.png" alt="Print">
            <s:label value="%{getText('reports.label')}"/></span>
    </s:a>
    <span class="module-title-breaker"> > </span>
    <s:a href="unAlienatedLandList.do">
        <span><img src="${pageContext.request.contextPath}/images/alienation-types/unalienated-land.png">
            <s:label value="%{getText('lands_available_for_alienation.label')}"/></span>
    </s:a>
</div>

<s:include value="../printCaller.jsp"/>
<div id="printDivId">

    <div class="page-title">
        <h2><s:label value="%{getText('lands_available_for_alienation.label')}"/></h2>
    </div>
    <table class="width-500-px margin-10-auto" id="filter-lists">
        <tr>
            <td><s:label value="%{getText('district.label')}"/></td>
            <td><s:textfield id="districtId" name="districtName" cssClass="width-200-px" disabled="true"/></td>
        </tr>
        <tr>
            <td><s:label value="%{getText('ds_division.label')}"/></td>
            <td><s:textfield id="dsDivisionId" name="dsDivisionName" cssClass="width-200-px" disabled="true"/></td>
        </tr>
        <tr>
            <td><s:label value="%{getText('gn_division.label')}"/></td>
            <td><s:select id="gnDivisionId" name="gnDivisionId" list="gnDivisionList" headerKey="0"
                          headerValue="%{getText('all.label')}" cssClass="width-200-px"/></td>
        </tr>
    </table>
    <div id="report-header">
        <table class="width-100 margin-10-auto">
            <tr>
                <td><s:label value="%{getText('district.label')}"/> : <s:textfield id="district"
                                                                                   cssStyle="border:none; background: none; color: #000;"
                                                                                   disabled="true"/></td>
            </tr>
            <tr>
                <td><s:label value="%{getText('ds_division.label')}"/> : <s:textfield id="ds-name"
                                                                                      cssStyle="border:none; background: none; color: #000;"
                                                                                      disabled="true"/></td>
            </tr>
            <tr>
                <td><s:label value="%{getText('gn_division.label')}"/> : <s:textfield id="gn-name"
                                                                                      cssStyle="border:none; background: none; color: #000;"
                                                                                      disabled="true"/></td>
            </tr>
        </table>
    </div>

    <div id="land-list">
        <%--<div id="printbtn" class="form-button-div right-align">
            &lt;%&ndash;<input type="button" value="Print" id="print"  class="print-btn">&ndash;%&gt;
            <input class="print-btn" type="button" value="Print" onclick="printAvailableLandPage();">

        </div>--%>
        <table class="width-100 margin-10-auto table land-table">

        </table>
    </div>
</div>


<%-- Localization text for java script generated text --%>
<s:hidden id="ref" value="%{getText('reference_no.label')}"/>
<s:hidden id="lname" value="%{getText('name_of_the_land.label')}"/>
<s:hidden id="plan" value="%{getText('plan_no.label')}"/>
<s:hidden id="lot" value="%{getText('lot_no.label')}"/>
<s:hidden id="vil" value="%{getText('village.label')}"/>
<s:hidden id="ext_pec" value="%{getText('extent_perches.label')}"/>
<s:hidden id="undifined" value="%{getText('undefined.label')}"/>

<%-- Localization text for data tables --%>
<s:hidden id="display" value="%{getText('display.label')}"/>
<s:hidden id="records" value="%{getText('records.label')}"/>
<s:hidden id="search" value="%{getText('search.label')}"/>
<s:hidden id="no-record" value="%{getText('no_record.label')}"/>
<s:hidden id="showing" value="%{getText('showing.label')}"/>
<s:hidden id="to" value="%{getText('to.label')}"/>
<s:hidden id="of" value="%{getText('of.label')}"/>
<s:hidden id="entries" value="%{getText('entries.label')}"/>
<s:hidden id="first" value="%{getText('first.label')}"/>
<s:hidden id="last" value="%{getText('last.label')}"/>
<s:hidden id="next" value="%{getText('next.label')}"/>
<s:hidden id="previous" value="%{getText('previous.label')}"/>